#!/bin/bash
#
# Copyright 2007	Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
#
# Makes sure either b43, b43legacy (new mac80211 drivers) or bcm43xx 
# is enabled to be used. This allows us to choose any driver without 
# blacklisting each other.

. /usr/lib/compat-wireless/modlib.sh

if [[ $UID -ne 0 ]]; then
	echo "Run with root privileges"
	exit
fi

B43S="b43 b43legacy"
B43_OLD="bcm43xx"
B43_PROP="wl"

# Appended to module file at the end when we want to ignore one
USAGE="Usage: $0 [ b43 | bcm43xx | wl ]"

function enable_b43 {
	module_disable $B43_OLD
	module_disable $B43_PROP
	for i in $B43S; do
		module_enable $i
	done
}

# Default behavior: disables the old bcm43xx driver and enables b43
# and b43legacy
if [ $# -eq 0 ]; then
	enable_b43
	exit
elif [ $# -ne 1 ]; then
	echo "$USAGE"
	exit
fi

MODULE=$1
if [ "$MODULE" == "bcm43xx" ]; then
	for i in $B43S; do
		module_disable $i
	done
	module_disable $B43_PROP
	module_enable $B43_OLD
elif [ "$MODULE" == "wl" ]; then
	for i in $B43S; do
		module_disable $i
	done
	module_disable $B43_OLD
	module_enable $B43_PROP
elif [ "$MODULE" == "b43" ]; then
	enable_b43
else
	echo "$USAGE"
	exit
fi
